package leo.manager
{
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	import leo.data.GameModel;
	import leo.data.MonsterVO;
	import leo.data.TowerVO;

	/**
	 * VO数据管理器 
	 * @author leo
	 * 
	 */
	public class VOManager
	{
		private static var _instance :VOManager = null;
		public function VOManager()
		{
		}
		
		public function getTowerVOByName(name :String):TowerVO
		{
			var vo :TowerVO;
			var towerVOList :Vector.<TowerVO> = GameModel.instance.towerVOList;
			for each(var towerVO :TowerVO in towerVOList)
			{
				if(towerVO.id == name)
				{
					vo = towerVO;
					break;
				}
			}
			if(!vo)
			{
				trace("getTowerVOByName have no this TowerVO");
			}
			return vo;
		}
		
		public function getMonsterVOByName(name :String):MonsterVO
		{
			var vo :MonsterVO;
			var monsterVOList :Vector.<MonsterVO> = GameModel.instance.monsterVOList;
			for each(var monsterVO :MonsterVO in monsterVOList)
			{
				if(monsterVO.id == name)
				{
					vo = monsterVO;
					break;
				}
			}
			if(!vo) trace("getTowerVOByName have no this MonsterVO");
			return vo;
		}
		
		public function copyMonsterVO(vo :MonsterVO):MonsterVO
		{
			registerClassAlias("leo.data.MonsterVO",MonsterVO);
			
			var byte :ByteArray =  new ByteArray();
			byte.writeObject(vo);
			byte.position = 0;
			return byte.readObject() as MonsterVO;
		}

		public static function get instance():VOManager
		{
			if(_instance == null)
			{
				_instance = new VOManager();
			}
			return _instance;
		}

	}
}